VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "DAOMEsa"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'---------------------------------------------------------------------------------------
' Module    : DAOMEsa
' DateTime  : 30/11/2011 12:12
' Author    :
' Purpose   : Clase DAO Mesa
'---------------------------------------------------------------------------------------
Option Explicit
Private mvarConnection As utilConexion
Public Property Set Connection(ByVal vData As utilConexion)
    Set mvarConnection = vData
End Property
Public Function getListaMesasxLiberar() As Collection
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bMesa
Dim nperfil As Integer
sql = "SELECT ncodigo, sdescripcion, nestado , sestado FROM proc_mesa_lista_x_liberar()"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
While Not rst.EOF
    Set record = New bMesa
    If Not IsNull(rst.Fields("nCodigo")) Then record.ncodigo = rst.Fields("ncodigo").value
    If Not IsNull(rst.Fields("sDescripcion")) Then record.sdescripcion = rst.Fields("sdescripcion").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.ncodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bEstado.sdescripcion = rst.Fields("sestado").value
    rst.MoveNext
    list.Add record
Wend
Set getListaMesasxLiberar = list
End Function

'@DEPRECATED
Public Function getLista(Optional bMesa As bMesa) As Collection
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bMesa
Dim nperfil As Integer
If Not bMesa Is Nothing Then
        sql = "SELECT ncodigo, sdescripcion, nestado , sestado FROM proc_mesa_lista_estado(" + CStr(bMesa.bEstado.ncodigo) + " )"
Else
    sql = "SELECT ncodigo, sdescripcion, nestado , sestado FROM proc_mesa_lista()"
End If
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
While Not rst.EOF
    Set record = New bMesa
    If Not IsNull(rst.Fields("nCodigo")) Then record.ncodigo = rst.Fields("ncodigo").value
    If Not IsNull(rst.Fields("sDescripcion")) Then record.sdescripcion = rst.Fields("sdescripcion").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.ncodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bEstado.sdescripcion = rst.Fields("sestado").value
    rst.MoveNext
    list.Add record
Wend
Set getLista = list
End Function
Public Function fn_validaCortez() As Integer
    Dim sql As String
    Dim rst As New Recordset
    Dim result As Integer
    sql = "Select * from proc_valida_Cortez(); "
    Set rst = mvarConnection.Connection.Execute(sql)
    result = rst(0).value
    fn_validaCortez = result
End Function
Public Function setLibre(bean As bMesa) As Integer
On Error GoTo hnderr
Dim sql As String
    sql = "SELECT * FROM proc_mesa_actualiza_estado(" + CStr(bean.ncodigo) + "," + CStr(UtilConstantes.ESTADO_MESA_LIBRE) + ");"
    mvarConnection.Connection.Execute sql
    setLibre = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    setLibre = UtilConstantes.OPT_ERROR_ENCONTRADO
End Function
Public Function setOcupada(bean As bMesa) As Integer
On Error GoTo hnderr
Dim sql As String
    sql = "SELECT * FROM proc_mesa_actualiza_estado(" + CStr(bean.ncodigo) + "," + CStr(UtilConstantes.ESTADO_MESA_OCUPADA) + ");"
    mvarConnection.Connection.Execute sql
    setOcupada = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    setOcupada = UtilConstantes.OPT_ERROR_ENCONTRADO
End Function
Public Function setEnCaja(bean As bMesa) As Integer
On Error GoTo hnderr
Dim sql As String
    sql = "SELECT * FROM proc_mesa_actualiza_estado(" + CStr(bean.ncodigo) + "," + CStr(UtilConstantes.ESTADO_MESA_ENCAJA) + ");"
    mvarConnection.Connection.Execute sql
    setEnCaja = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    setEnCaja = UtilConstantes.OPT_ERROR_ENCONTRADO
End Function
Public Function setReservada(bean As bMesa) As Integer
On Error GoTo hnderr
Dim sql As String
    sql = "SELECT * FROM proc_mesa_actualiza_estado(" + CStr(bean.ncodigo) + "," + CStr(UtilConstantes.ESTADO_MESA_RESERVADA) + ");"
    mvarConnection.Connection.Execute sql
    setReservada = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    setReservada = UtilConstantes.OPT_ERROR_ENCONTRADO
End Function

